Skip to main content
Glama
ZephyrDeng

mcp-server-gitlab

Gitlab Create MR Comment Tool

Add comments to merge requests in GitLab projects to streamline code review and collaboration. Specify project ID, merge request ID, and comment content for effective feedback.

Instructions

为指定项目的合并请求添加评论。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commentYes评论内容
fieldsNo需要返回的字段路径数组
mergeRequestIdYes合并请求 ID
projectIdYes项目 ID

Implementation Reference

  • The `execute` method implementing the tool's core logic: resolves project ID, makes POST request to GitLab API to create MR comment, filters response if fields specified, handles errors.
    async execute(args: unknown, context: Context<Record<string, unknown> | undefined>) {
      const typedArgs = args as {
        projectId: string | number;
        mergeRequestId: number;
        comment: string;
        fields?: string[];
      };
      
      const { projectId: projectIdOrName, mergeRequestId, comment, fields } = typedArgs;
    
      try {
        const client = createGitlabClientFromContext(context);
        const resolvedProjectId = await client.resolveProjectId(projectIdOrName);
        if (!resolvedProjectId) {
          throw new Error(`无法解析项目 ID 或名称:${projectIdOrName}`);
        }
    
        const endpoint = `/projects/${encodeURIComponent(String(resolvedProjectId))}/merge_requests/${mergeRequestId}/notes`;
        const response = await client.apiRequest(endpoint, "POST", undefined, { body: comment });
    
        if (!client.isValidResponse(response)) {
          throw new Error(`GitLab API error: ${response?.message || 'Unknown error'}`);
        }
    
        if (fields) {
          const filteredResponse = filterResponseFields(response, fields);
          return {
            content: [{ type: "text", text: JSON.stringify(filteredResponse) }]
          } as ContentResult;
        }
        
        return {
          content: [{ type: "text", text: JSON.stringify(response) }]
        } as ContentResult;
      } catch (error: any) {
        return {
          content: [
            {
              type: "text",
              text: `GitLab MCP 工具调用异常:${error?.message || String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters: projectId (string|number), mergeRequestId (number), comment (string), optional fields (string[]).
    parameters: z.object({
      projectId: z.union([z.string(), z.number()]).describe("项目 ID 或名称"),
      mergeRequestId: z.number().describe("合并请求 ID"),
      comment: z.string().describe("评论内容"),
      fields: z.array(z.string()).optional().describe("需要返回的字段路径数组"),
    }),
  • The `fastmcpTools` array including GitlabCreateMRCommentTool, used for registration.
    const fastmcpTools = [
      GitlabAcceptMRTool,
      GitlabCreateMRCommentTool,
      GitlabCreateMRTool,
      GitlabGetUserTasksTool,
      GitlabRawApiTool,
      GitlabSearchProjectDetailsTool,
      GitlabSearchUserProjectsTool,
      GitlabUpdateMRTool,
    ];
  • The registration loop in `registerGitLabToolsForFastMCP` that calls `server.addTool(tool)` for filtered tools.
    fastmcpTools.forEach(tool => {
      const standardizedName = toolNameMapping[tool.name as keyof typeof toolNameMapping];
      if (shouldRegisterTool(standardizedName as GitLabToolName, options.toolFilter)) {
        // GitLabTool is now fully compatible with FastMCP's base type, can be registered directly
        server.addTool(tool);
      }
    });
  • Tool name mapping from internal name to standardized name used in filtering.
    [GitlabCreateMRCommentTool.name]: "Gitlab_Create_MR_Comment_Tool",
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('添加评论') which implies a write operation, but doesn't describe permissions required, rate limits, whether comments are editable/deletable, or what happens on success/failure. For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core action, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't address behavioral aspects like permissions or error handling, nor does it explain the purpose of the optional 'fields' parameter or what the tool returns. More context is needed given the complexity and lack of structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters (projectId, mergeRequestId, comment, fields). The description doesn't add any parameter-specific context beyond what's in the schema, such as format examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('添加评论' - add comment) and resource ('指定项目的合并请求' - specified project's merge request). It distinguishes from siblings like 'Gitlab Accept MR Tool' or 'Gitlab Update MR Tool' by focusing on commenting rather than merging or modifying the MR itself. However, it doesn't explicitly differentiate from potential commenting alternatives that might exist in other contexts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing MR), exclusions, or comparisons with sibling tools like 'Gitlab Raw API Tool' which might also handle comments. Usage is implied through the action but not explicitly contextualized.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZephyrDeng/mcp-server-gitlab'

If you have feedback or need assistance with the MCP directory API, please join our Discord server